DOM4J cannot save the XML file as UTF-8, Invalid byte 2 of 2-byte UTF-8 Sequence-hxzon hands-gdo
These days began to learn dom4j, on the Internet to find an article on the dry, very fast, but found a problem is not to UTF-8 save the XML file, save
Copy CodeThe code is as follows:
Include ' mysql.php ';$mysql = Mysql::getobject ();$mysql->query ("select * from post");$xml = new XMLWriter ();$xml->openuri (' hello.xml '); or ' Php://output '$xml->setindentstring (");$xml->setindent
Copy codeThe Code is as follows:Include 'mysql. php ';$ Mysql = mysql: getObject ();$ Mysql-> query ("SELECT * FROM post ");$ Xml = new XMLWriter ();$ Xml-> openUri ('hello. xml'); // or 'php: // output'$ Xml-> setIndentString ('');$ Xml-> setIndent
XML read exception invalid byte 1 of 1-byte UTF-8 Sequence
To put it simply, this error may occur when you parse other users' XML formats, that is, when others generate xml, they do not save it as a UTF-8 character encoding format.
In Windows of
Copy codeThe Code is as follows: include 'mysql. php ';
$ Mysql = mysql: getObject ();
$ Mysql-> query ("SELECT * FROM post ");
$ Xml = new XMLWriter ();$ Xml-> openUri ('hello. xml'); // or 'php: // output'$ Xml-> setIndentString ('');$ Xml->
When parsing xml with PHP prompt invalid byte 1 of 1-byte UTF-8 sequence error, this problem I Baidu verified that is coding problem, the result I put the code to deal with really KO, below I to share the solution.
Error hints
Invalid byte 1 of
Error tipsInvalid byte 1 of 1-byte UTF-8 sequenceCause analysisIn the Chinese version of Windows, the default encoding of Java is GBK, which means that although we identify the XML to be saved as Utf-8 format but actually the file is saved in GBK
Garbled characters appear when you use dom4j xmlwriter to output UTF-8-encoded XML files.
First, set the output encoding where we use UTF-8: Java
Code :
Outputformat format = outputformat. createprettyprint (); format. setencoding ("UTF-8 ");
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.